home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / misc / date.lha / Date / C / src / testlib.c < prev    next >
C/C++ Source or Header  |  1994-08-02  |  14KB  |  407 lines

  1.  #include <exec/exec.h>
  2.  #include <proto/exec.h>
  3.  #include <stdio.h>
  4.  #include "Date.h"
  5.  #include "Date_pragmas.h"
  6.  
  7.  
  8.  int readintyear(void)
  9.  
  10.  {int year=0;
  11.  
  12.   printf("(integer)year: ");
  13.   scanf("%d",&year);
  14.   return(year);
  15.  }
  16.  
  17.  
  18.  unsigned short readshortcardmonth(void)
  19.  
  20.  {unsigned int month=0;
  21.  
  22.   printf("(shortcard)month: ");
  23.   scanf("%u",&month);
  24.   return((unsigned short)month);
  25.  }
  26.  
  27.  
  28.  unsigned short readshortcardday(void)
  29.  
  30.  {unsigned int day=0;
  31.  
  32.   printf("(shortcard)day: ");
  33.   scanf("%u",&day);
  34.   return((unsigned short)day);
  35.  }
  36.  
  37.  
  38.  Weekdays readweekday(void)
  39.  
  40.  {unsigned int wday=0;
  41.  
  42.   do
  43.    {printf("weekday: 1=Monday; ...7=Sunday: ");
  44.     scanf("%u",&wday);
  45.    }
  46.   while (wday > 7);
  47.   return((Weekdays)wday);
  48.  }
  49.  
  50.  
  51.  Weekdays readintdays(void)
  52.  
  53.  {int days=0;
  54.  
  55.   printf("(integer)days: ");
  56.   scanf("%d",&days);
  57.   return(days);
  58.  }
  59.  
  60.  
  61.  unsigned int readcardyear(void)
  62.  
  63.  {unsigned int year=0;
  64.  
  65.   printf("(cardinal)year: ");
  66.   scanf("%u",&year);
  67.   return(year);
  68.  }
  69.  
  70.  
  71.  unsigned long readlongcarddays(void)
  72.  
  73.  {unsigned long day=0;
  74.  
  75.   printf("(longcard)days: ");
  76.   scanf("%u",&day);
  77.   return(day);
  78.  }
  79.  
  80.  
  81.  unsigned short readshortcardhour(void)
  82.  
  83.  {unsigned int hour=0;
  84.  
  85.   printf("(shortcard)hour: ");
  86.   scanf("%u",&hour);
  87.   return((unsigned short)hour);
  88.  }
  89.  
  90.  
  91.  unsigned short readshortcardmin(void)
  92.  
  93.  {unsigned int min=0;
  94.  
  95.   printf("(shortcard)min: ");
  96.   scanf("%u",&min);
  97.   return((unsigned short)min);
  98.  }
  99.  
  100.  
  101.  unsigned short readshortcardsec(void)
  102.  
  103.  {unsigned int sec=0;
  104.  
  105.   printf("(shortcard)sec: ");
  106.   scanf("%u",&sec);
  107.   return((unsigned short)sec);
  108.  }
  109.  
  110.  
  111.  float readrealtime(void)
  112.  
  113.  {float jd=0.0;
  114.  
  115.   printf("(real)time: ");
  116.   scanf("%f",&jd);
  117.   return(jd);
  118.  }
  119.  
  120.  
  121.  short readshortintdegree(void)
  122.  
  123.  {int degree=0;
  124.  
  125.   printf("(shortint)degree: ");
  126.   scanf("%d",°ree);
  127.   return((short)degree);
  128.  }
  129.  
  130.  
  131.  unsigned long readlongcardsecs(void)
  132.  
  133.  {unsigned long secs=0;
  134.  
  135.   printf("(longcard)secs: ");
  136.   scanf("%u",&secs);
  137.   return(secs);
  138.  }
  139.  
  140.  
  141.  float readrealmeridian(void)
  142.  
  143.  {float jd=0.0;
  144.  
  145.   printf("(real)meridian: ");
  146.   scanf("%f",&jd);
  147.   return(jd);
  148.  }
  149.  
  150.  
  151.  float readrealpos(void)
  152.  
  153.  {float jd=0.0;
  154.  
  155.   printf("(real)ps: ");
  156.   scanf("%f",&jd);
  157.   return(jd);
  158.  }
  159.  
  160.  
  161.  void main(void)
  162.  
  163.  {unsigned int        input=0,repeat=0;
  164.   Weekdays        wd;
  165.   unsigned short    d=0,m=0,h=0,s=0;
  166.   int            y=0;
  167.  
  168.   struct Library *DateBase;
  169.  
  170. DateBase = OpenLibrary("Date.library",0);
  171. if (DateBase != NULL) {
  172.   do
  173.    {printf("----------------------------------------------------------------\n");
  174.     printf("01 : JulianLeapYear            | 02 : GregorianLeapYear\n");
  175.     printf("03 : HeisLeapYear              | 04 : JulianMonthDays\n");
  176.     printf("05 : GregorianMonthDays        | 06 : HeisMonthDays\n");
  177.     printf("07 : JulianYearDays            | 08 : GregorianYearDays\n");
  178.     printf("09 : HeisYearDays              | 10 : JulianDayDiff\n");
  179.     printf("11 : GregorianDayDiff          | 12 : HeisDayDiff\n");
  180.     printf("13 : JulianDaySmaller          | 14 : GregorianDaySmaller\n");
  181.     printf("15 : HeisDaySmaller            | 16 : JulianWeekday\n");
  182.     printf("17 : GregorianWeekday          | 18 : HeisWeekday\n");
  183.     printf("19 : JulianDaysBeforeWeekday   | 20 : GregorianDaysBeforeWeekday\n");
  184.     printf("21 : HeisDaysBeforeWeekday     | 22 : JulianDaysAfterWeekday\n");
  185.     printf("23 : GregorianDaysAfterWeekday | 24 : HeisDaysAfterWeekday\n");
  186.     printf("25 : JulianDiffDate            | 26 : GregorianDiffDate\n");
  187.     printf("27 : HeisDiffDate              | 28 : JYearToScaliger\n");
  188.     printf("29 : GYearToScaliger           | 30 : HYearToScaliger\n");
  189.     printf("31 : ScaligerYearToJ           | 32 : ScaligerYearToG\n");
  190.     printf("33 : ScaligerYearToH           | 34 : JSYearToJD\n");
  191.     printf("35 : GSYearToJD                | 36 : HSYearToJD\n");
  192.     printf("37 : JDtoMJD                   | 38 : MJDtoJD\n");
  193.     printf("39 : JulianToJD                | 40 : GregorianToJD\n");
  194.     printf("41 : HeisToJD                  | 42 : TimeToJD\n");
  195.     printf("43 : JDToTime                  | 44 : GregorianMoonAge\n");
  196.     printf("45 : GregorianEaster           | 46 : TimeZoneFactor\n");
  197.     printf("47 : LMT                       | 48 : TimeToSec\n");
  198.     printf("49 : SecToTime                 | 50 : JulianWeek\n");
  199.     printf("51 : GregorianWeek             | 52 : HeisWeek\n");
  200.     printf("00 : Quit\n");
  201.     printf("It's your turn: ");
  202.     scanf("%u",&input);
  203.     printf("----------------------------------------------------------------\n");
  204.     do
  205.      {switch (input)
  206.         {
  207.          case  0 : break;
  208.          case  1 : if (JulianLeapYear(readintyear()))
  209.                      printf("TRUE\n");
  210.                 else
  211.                   printf("FALSE\n");
  212.                break;
  213.          case  2 : if (GregorianLeapYear(readintyear()))
  214.                  printf("TRUE\n");
  215.                 else
  216.                   printf("FALSE\n");
  217.                    break;
  218.          case  3 : if (HeisLeapYear(readintyear()))
  219.                   printf("TRUE\n");
  220.                 else
  221.                   printf("FALSE\n");
  222.                break;
  223.          case  4 : printf("%u\n",JulianMonthDays(readshortcardmonth(),readintyear()));
  224.                    break;
  225.          case  5 : printf("%u\n",GregorianMonthDays(readshortcardmonth(),readintyear()));
  226.                    break;
  227.          case  6 : printf("%u\n",HeisMonthDays(readshortcardmonth(),readintyear()));
  228.                    break;
  229.          case  7 : printf("%u\n",JulianYearDays(readintyear()));
  230.                    break;
  231.          case  8 : printf("%u\n",GregorianYearDays(readintyear()));
  232.                break;
  233.          case  9 : printf("%u\n",HeisYearDays(readintyear()));
  234.                break;
  235.          case 10 : printf("%d\n",JulianDayDiff(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()));
  236.                break;
  237.          case 11 : printf("%d\n",GregorianDayDiff(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()));
  238.                break;
  239.          case 12 : printf("%d\n",HeisDayDiff(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()));
  240.                break;
  241.          case 13 : if (JulianDaySmaller(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()))
  242.                   printf("TRUE\n");
  243.                 else
  244.                   printf("FALSE\n");
  245.                break;
  246.          case 14 : if (GregorianDaySmaller(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()))
  247.                   printf("TRUE\n");
  248.                 else
  249.                   printf("FALSE\n");
  250.                break;
  251.          case 15 : if (HeisDaySmaller(readshortcardday(),readshortcardmonth(),readintyear(),readshortcardday(),readshortcardmonth(),readintyear()))
  252.                   printf("TRUE\n");
  253.                 else
  254.                   printf("FALSE\n");
  255.                break;
  256.          case 16 : wd = JulianWeekday(readshortcardday(),readshortcardmonth(),readintyear());
  257.                      switch (wd)
  258.                        {case dayerr    : printf("dayerr!\n");
  259.                                    break;
  260.                       case Monday    : printf("Monday\n");
  261.                                    break;
  262.                       case Tuesday   : printf("Tuesday\n");
  263.                                    break;
  264.                       case Wednesday : printf("Wednesday\n");
  265.                                    break;
  266.                       case Thursday  : printf("Thursday\n");
  267.                                    break;
  268.                       case Friday    : printf("Friday\n");
  269.                                    break;
  270.                       case Saturday  : printf("Saturday\n");
  271.                                    break;
  272.                       case Sunday    : printf("Sunday\n");
  273.                                        break;
  274.                       default        : printf("Illegal Code!\n");
  275.                      }
  276.                break;
  277.          case 17 : wd = GregorianWeekday(readshortcardday(),readshortcardmonth(),readintyear());
  278.                      switch (wd)
  279.                        {case dayerr    : printf("dayerr!\n");
  280.                                    break;
  281.                       case Monday    : printf("Monday\n");
  282.                                    break;
  283.                       case Tuesday   : printf("Tuesday\n");
  284.                                    break;
  285.                       case Wednesday : printf("Wednesday\n");
  286.                                    break;
  287.                       case Thursday  : printf("Thursday\n");
  288.                                    break;
  289.                       case Friday    : printf("Friday\n");
  290.                                    break;
  291.                       case Saturday  : printf("Saturday\n");
  292.                                    break;
  293.                       case Sunday    : printf("Sunday\n");
  294.                                        break;
  295.                       default        : printf("Illegal Code!\n");
  296.                      }
  297.                break;
  298.          case 18 : wd = HeisWeekday(readshortcardday(),readshortcardmonth(),readintyear());
  299.                      switch (wd)
  300.                        {case dayerr    : printf("dayerr!\n");
  301.                                    break;
  302.                       case Monday    : printf("Monday\n");
  303.                                    break;
  304.                       case Tuesday   : printf("Tuesday\n");
  305.                                    break;
  306.                       case Wednesday : printf("Wednesday\n");
  307.                                    break;
  308.                       case Thursday  : printf("Thursday\n");
  309.                                    break;
  310.                       case Friday    : printf("Friday\n");
  311.                                    break;
  312.                       case Saturday  : printf("Saturday\n");
  313.                                    break;
  314.                       case Sunday    : printf("Sunday\n");
  315.                                        break;
  316.                       default        : printf("Illegal Code!\n");
  317.                      }
  318.                break;
  319.          case 19 : printf("%u\n",JulianDaysBeforeWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  320.                break;
  321.          case 20 : printf("%u\n",GregorianDaysBeforeWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  322.                break;
  323.          case 21 : printf("%u\n",HeisDaysBeforeWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  324.                break;
  325.          case 22 : printf("%u\n",JulianDaysAfterWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  326.                break;
  327.          case 23 : printf("%u\n",GregorianDaysAfterWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  328.                break;
  329.          case 24 : printf("%u\n",HeisDaysAfterWeekday(readshortcardday(),readshortcardmonth(),readintyear(),readweekday()));
  330.                break;
  331.          case 25 : JulianDiffDate(readshortcardday(),readshortcardmonth(),readintyear(),readintdays(),&d,&m,&y);
  332.                    printf("%u.%u.%d\n",d,m,y);
  333.                break;
  334.          case 26 : GregorianDiffDate(readshortcardday(),readshortcardmonth(),readintyear(),readintdays(),&d,&m,&y);
  335.                    printf("%u.%u.%d\n",d,m,y);
  336.                break;
  337.          case 27 : HeisDiffDate(readshortcardday(),readshortcardmonth(),readintyear(),readintdays(),&d,&m,&y);
  338.                    printf("%u.%u.%d\n",d,m,y);
  339.                break;
  340.          case 28 : printf("%u\n",JYearToScaliger(readintyear()));
  341.                break;
  342.          case 29 : printf("%u\n",GYearToScaliger(readintyear()));
  343.                break;
  344.          case 30 : printf("%u\n",HYearToScaliger(readintyear()));
  345.                break;
  346.          case 31 : printf("%d\n",ScaligerYearToJ(readcardyear()));
  347.                break;
  348.          case 32 : printf("%d\n",ScaligerYearToG(readcardyear()));
  349.                break;
  350.          case 33 : printf("%d\n",ScaligerYearToH(readcardyear()));
  351.                break;
  352.          case 34 : printf("%u\n",JSYearToJD(readcardyear()));
  353.                break;
  354.          case 35 : printf("%u\n",GSYearToJD(readcardyear()));
  355.                break;
  356.          case 36 : printf("%u\n",HSYearToJD(readcardyear()));
  357.                break;
  358.          case 37 : printf("%u\n",JDtoMJD(readlongcarddays()));
  359.                break;
  360.          case 38 : printf("%u\n",MJDtoJD(readlongcarddays()));
  361.                break;
  362.          case 39 : printf("%u\n",JulianToJD(readshortcardday(),readshortcardmonth(),readintyear()));
  363.                break;
  364.          case 40 : printf("%u\n",GregorianToJD(readshortcardday(),readshortcardmonth(),readintyear()));
  365.                break;
  366.          case 41 : printf("%u\n",HeisToJD(readshortcardday(),readshortcardmonth(),readintyear()));
  367.                break;
  368.          case 42 : printf("%f\n",TimeToJD(readshortcardhour(),readshortcardmin(),readshortcardsec()));
  369.                    break;
  370.          case 43 : JDToTime(readrealtime(),&h,&m,&s);
  371.                    printf("%u:%u:%u\n",h,m,s);
  372.                break;
  373.          case 44 : printf("%u\n",GregorianMoonAge(readshortcardday(),readshortcardmonth(),readintyear()));
  374.                break;
  375.          case 45 : GregorianEaster(readintyear(),&d,&m);
  376.                    printf("%u.%u.\n",d,m);
  377.                break;
  378.          case 46 : printf("%d\n",TimeZoneFactor(readshortintdegree()));
  379.                break;
  380.          case 47 : printf("%d\n",LMT(readlongcardsecs(),readrealmeridian(),readrealpos()));
  381.                break;
  382.          case 48 : printf("%u\n",TimeToSec(readshortcardhour(),readshortcardmin(),readshortcardsec()));
  383.                break;
  384.          case 49 : SecToTime(readlongcardsecs(),&h,&m,&s);
  385.                    printf("%u:%u:%u\n",h,m,s);
  386.                break;
  387.      case 50 : printf("%u\n",JulianWeek(readshortcardday(),readshortcardmonth(),readintyear()));
  388.            break;
  389.      case 51 : printf("%u\n",GregorianWeek(readshortcardday(),readshortcardmonth(),readintyear()));
  390.            break;
  391.      case 52 : printf("%u\n",HeisWeek(readshortcardday(),readshortcardmonth(),readintyear()));
  392.            break;
  393.          default : printf("Wong number! Try again!\n");
  394.         }
  395.       if (input > 0)
  396.         {printf("0 : Menue; >0 : test again - ");
  397.          scanf("%u",&repeat);
  398.         }
  399.       else
  400.         repeat = 0;
  401.      }
  402.     while (repeat != 0);
  403.    }
  404.   while (input != 0);
  405. CloseLibrary(DateBase);}
  406.  }
  407.